using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Factories;

namespace TileEngine
{
    public class EnemyManager : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Enemy[] enemies;
        SpriteBatch spriteBatch;

        CelAnimationManager cam;

        public EnemyManager(Game game)
            : base(game)
        {
            enemies = new Enemy[30];
            cam = (CelAnimationManager)game.Services.GetService(typeof(ICelAnimationManager));
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            cam.AddAnimation("cricket", "cricket", new CelCount(1, 1), 1);
            base.LoadContent();
        }

        public void Load(SpriteBatch spriteBatch, PhysicsSimulator physicsSimulator)
        {
            this.spriteBatch = spriteBatch;

            for (int i = 0; i < enemies.Length; i++)
            {

                enemies[i] = new Enemy();
                physicsSimulator.Add(enemies[i].body);
                enemies[i].geom.SetBody(enemies[i].body);
                physicsSimulator.Add(enemies[i].geom);     
                
            }
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            for (int i = 0; i < enemies.Length; i++)
            {
                if (enemies[i] != null)
                {
                    cam.Draw(gameTime, "cricket", spriteBatch, enemies[i].body.Position, Color.White, SpriteEffects.None, enemies[i].body.Rotation);
                }
            }

            base.Draw(gameTime);
        }
    }
}